﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Newtonsoft.Json;
using System.Text;

public partial class 测试_table : System.Web.UI.Page
{
    StringBuilder dt = new StringBuilder();
    private static int row = 0;
    private static int column = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        string param = Request["param"];
        if (param == "2013-1-7")
        {
            //李东峰
        }
        if (param != "")
        {
            if (param == "query")
            {
                row = Convert.ToInt32(Request["row"]);
                column = Convert.ToInt32(Request["column"]);
                GetTableInfo(row, column);
            }
            else if (param == "save")
            {
                int rowStart = Convert.ToInt32(Request["rowStart"]);
                int rowEnd = Convert.ToInt32(Request["rowEnd"]);
                int columnStart = Convert.ToInt32(Request["columnStart"]);
                int columnEnd = Convert.ToInt32(Request["columnEnd"]);
                GetTableSaveInfo(rowStart, columnStart, rowEnd, columnEnd);
            }
            else if (param == "OK")
            {
                int r = 0;
            }
            else if (param == "NO")
            {
                int R = 0;
            }
        }
    }
    //border:solid Blue 1px;

    protected void GetTableInfo(int row, int column)
    {
        dt.Append("<table border=\"1\" style=\"width:80%;\">");
        for (int i = 0; i < row; i++)
        {
            dt.Append("<tr style=\"border:solid Blue 1px;\">");
            for (int k = 0; k < column; k++)
            {
                dt.Append("<td><input type=\"text\" id=\"txt" + i + "_" + k + "\" style=\"text-align: center;width:80%;\"/></td>");
            }
            dt.Append("</tr>");
        }
        dt.Append("</table>");
        object obj = new
                    {
                        tableinfo = dt.ToString()
                    };

        string result = JavaScriptConvert.SerializeObject(obj);
        Response.Write(result);
        Response.End();
    }

    protected void GetTableSaveInfo(int rowStart, int columnStart, int rowEnd, int columnEnd)
    {
        int count = 0;
        int num = 0;
        count = columnEnd - columnStart + 1;
        num = rowEnd - rowStart;
        dt.Append("<table border=\"1\" style=\"width:80%;\">");
        for (int i = 0; i < row; i++)
        {
            dt.Append("<tr style=\"border:solid Blue 1px;\">");
            //合并单独行
            if (rowStart == rowEnd)
            {
                if (rowStart - 1 == i)
                {
                    for (int k = 0; k <= column - count; k++)
                    {
                        if (k == columnStart - 1)
                            dt.Append("<td colspan=\"" + count + "\"><input type=\"text\" id=\"txt" + i + "_" + k + "\" style=\"text-align: center;width:80%;\"/></td>");
                        else
                            dt.Append("<td><input type=\"text\" id=\"txt" + i + "_" + k + "\" style=\"text-align: center;width:80%;\"/></td>");
                    }
                }
                else
                {
                    for (int k = 0; k < column; k++)
                    {
                        dt.Append("<td><input type=\"text\" id=\"txt" + i + "_" + k + "\" style=\"text-align: center;width:80%;\"/></td>");
                    }
                }
            }
            else
            {
                //合并多行
            }
            dt.Append("</tr>");
        }
        dt.Append("</table>");
        object obj = new
        {
            tableinfo = dt.ToString()
        };


        string result = JavaScriptConvert.SerializeObject(obj);
        Response.Write(result);
        Response.End();
    }
}
